package tech.aistar.controller;

import jakarta.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import tech.aistar.service.UserService;
import tech.aistar.util.ImageUtils;
import tech.aistar.vo.Result;
import java.io.IOException;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("file")
public class FileController {
@Autowired
private ImageUtils imageUtils;

@Autowired
private UserService  userService;


    @ResponseBody
    @PostMapping("test")
    public Result img(MultipartFile[] file, HttpServletRequest request) throws IOException {//大部分的前端文件上传的插件的名称都是file

        if(ObjectUtils.isEmpty(file)){
            return new Result("500","请选择上传的文件!");
        }

        Map<String, List<String>> uploadImagesUrl = imageUtils.uploadImages(file);
//        System.out.println(uploadImagesUrl);

        return new Result("200","上传成功",uploadImagesUrl);


    }
}
